package com.cn.ycy.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;

import java.time.LocalDateTime;

public class HelloJob1 implements Job {

    @Override
    public void execute(JobExecutionContext context) {
        Object tv1 = context.getTrigger().getJobDataMap().get("TriggerKey1");
        Object tv2 = context.getTrigger().getJobDataMap().get("TriggerKey2");
        Object jv1 = context.getJobDetail().getJobDataMap().get("j1");
        Object jv2 = context.getJobDetail().getJobDataMap().get("j2");
        Object sv = null;
        try {
            sv = context.getScheduler().getContext().get("skey");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        if ("ex".equalsIgnoreCase(String.valueOf(tv1))) {
            //如果抛出一个 异常 查看效果
            throw new RuntimeException("抛出一个异常,查看日志");
        }
        System.out.println(tv1 + ":" + tv2);
        System.out.println(jv1 + ":" + jv2);
        System.out.println(sv);
        System.out.println("hello1:" + LocalDateTime.now());
    }
}
